package mi.paq;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import entidades.*;

public class PlatosDAO {
	
	static String urlConex="jdbc:mysql://192.168.0.200:3306/db_resto";	
	static String user = "root";
	static String password = "nocdfound";
	
	public PlatosDAO() {
		
	}
	
	public static int getCantPlatos(int tipoPlato) {
		
		Integer cantPlatos=0;
    	try {
    		Class.forName("com.mysql.jdbc.Driver").newInstance();
			Connection con = DriverManager.getConnection(urlConex, user, password);
			Statement select = 	con.createStatement();
			String Consulta = "SELECT count(*) FROM platos p WHERE p.idtipoplato = " + tipoPlato;
			ResultSet result = select.executeQuery(Consulta);
			
			result.next();
			cantPlatos=result.getInt(1);
			
			select.close();
			con.close();
			
			return cantPlatos;
			
		} catch (Exception e) {
			e.printStackTrace();
			
		}
    	
		return cantPlatos;
		
		
	}
	
	public Platos getAllPlatos() {
		Platos oPlatos =  new Platos();
		Plato oPlato;
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			Connection con = DriverManager.getConnection(urlConex, user, password);
			Statement select = 	con.createStatement();
			String Consulta = "";
			ResultSet result = select.executeQuery(Consulta);
			while (result.next()) {
				oPlato =  new Plato();
				oPlato.setIdPlato(result.getInt("idplato"));
				oPlato.setDescripcion(result.getString("descripcion"));
				oPlato.setInfoAlternativa(result.getString("infoAlternativa"));
				oPlato.setRutaImagen(result.getString("rutaImagen"));
				oPlato.setIdTipoPlato(result.getInt("idtipoPlato"));
				oPlatos.add(oPlato);
				
			}
			
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		finally
		{
			
		}
		
		return oPlatos;
		
	}
	
	
}




